package com.ruoyi.web.controller.power;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.baidu.Base64Util;
import com.ruoyi.common.utils.baidu.Util;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.framework.web.domain.server.Sys;
import com.ruoyi.power.Vo.ReqParam;
import com.ruoyi.power.bangongwendang.BgwdBack;
import com.ruoyi.power.bangongwendang.BgwdReq;
import com.ruoyi.power.service.RequestService;
import com.ruoyi.power.shouxieshibie.SxsbBack;
import com.ruoyi.power.shouxieshibie.SxsbReq;
import com.ruoyi.power.tongyong.TyBack;
import com.ruoyi.power.tongyong.TyReq;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/power/ocr")
public class TOcrController extends BaseController {
    @Value("${powerservice.orcurl}")
    private String orcurl;
    @Value("${powerservice.apitongyong}")
    private String apitongyong;
    @Value("${powerservice.apishouxieshibie}")
    private String apishouxieshibie;
    @Value("${powerservice.apibangongwendang}")
    private String apibangongwendang;

    @PostMapping("/uploadfiles")
    public AjaxResult uploadfiles(MultipartFile file, String ocrtype) throws Exception {
        AjaxResult ajaxResult = new AjaxResult();
        try {
            String url = "";
            if (StringUtils.isNotEmpty(ocrtype)) {
                if (ocrtype.equals("tongyong")) {
                    url = orcurl + apitongyong;
                    ajaxResult = RequestService.gettongyong(url, file);
                } else if (ocrtype.equals("shouxieshibie")) {
                    url = orcurl + apishouxieshibie;
                    ajaxResult = RequestService.getshouxieshibie(url, file);
                } else if (ocrtype.equals("bangongwendang")) {
                    url = orcurl + apibangongwendang;
                    ajaxResult = RequestService.getbangongwendang(url, file);
                }
                return ajaxResult;
            } else {
                return AjaxResult.error("识别类型不能为空，请选择后上传识别文件");
            }
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }
}
